# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/8/7
# @File : B. Splitting an Array.py

"""
Given an array of n positive integers. Your task is to divide it into k segments so that the maximum sum on the segment is the minimum possible.

"""

def check(mid):  # 判断全部分段和都不能大于mid，贪心策略。
    # 其实不用找出来每一段，只是需要判断一下是否全部分段的和都小于mid就行。
    sum = 0
    seg = 0
    tag = 0
    for i in range(n):
        if (rate[i] > mid):
            tag = 1
        if (sum + rate[i] <= mid):
            sum = sum + rate[i]
        else:
            sum = rate[i]
            seg += 1
    seg += 1#数段数

    return seg <= k and tag == 0


def bi():
    l = 0
    r = (n - k + 1) * 10 ** 9#一定要有K段，所以r最大值也不可能超过k-1个段都是只有一个元素，然后一个段有n-k+1个元素，然后元素全是10 ** 9
    while (l + 1 < r):
        mid = (l + r) // 2
        if (check(mid)):#如果返回真，说明当前的和（mid）大了，因为有最大的段的和比mid小的，所以mid就可以继续减小
            r = mid
        else:#如果返回假，说明mid小了，因为有某段的和比当前mid要大，所以mid要增大
            l = mid
    return r


if __name__ == "__main__":
    """
    右二分，找满足条件的最小值，即不小于的最小
    0000001111111，找最小的1。
    二分和
    找最小的和,使得k个分段的和都不能大于这个和，即k个分段的和的最大的那个也不能大于。
    """
    n, k = map(int, input().split())
    rate = [int(i) for i in input().split()]
    print(bi())
